/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author kylin
 */
public class TestThreadShutdown {
    public static void main(String args[]){
        MyThread7 r=new MyThread7();
        Thread th=new Thread(r);
        th.start();
        System.out.println("Thread is running");
    }
}

class MyThread7 implements Runnable{
    boolean flag=true;
    int counter=1;
    @Override
    public void run() {
        while(flag){
            Date date=new Date();
            SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
            System.out.println("current time: "+format.format(date)+" "+Thread.currentThread().isAlive());
            counter++;
            try{
                Thread.sleep(1000);
            }catch(InterruptedException e){
                return;
            }
            if(counter>=61){
                this.shutdown();
            }
        }
    }
    public void shutdown(){
        flag=false;
    }

}